{extend name='public/list'/}
<!-- 搜索字段 -->
{block name='fields'}
<div class="layui-inline">
    <label class="layui-form-label">网站名称</label>
    <div class="layui-input-block">
        <input type="text" name="name" value="" placeholder="请输入网站名称" class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <label class="layui-form-label">网站地址</label>
    <div class="layui-input-block">
        <input type="text" name="url" value="" placeholder="请输入网站地址" class="layui-input">
    </div>
</div>
{/block}
<!-- js -->
{block name='js'}
<script>
    var cols = [
        [{
            checkbox: true,
            fixed: 'left',
        }, {
            field: 'id',
            title: 'ID',
            sort: true,
        }, {
            field: 'name',
            title: '网站名称',
        }, {
            field: 'url',
            title: '网站地址',
        }, {
            field: 'logo',
            title: 'Logo',
            sort: true,
        }, {
            field: 'sort',
            title: '排序',
            edit: 'text',
            sort: true,
        }, {
            field: 'status',
            title: '状态',
            sort: true,
            width: 95,
            templet: function (res) {
                return '<input type="checkbox" value="' + res.id + '" lay-filter="status" lay-text="开启|禁用" lay-skin="switch"' + (res.status == 0 ? ' checked' : '') + '>';
            }
        }, {
            field: 'time',
            title: '时间',
            sort: true,
        }, {
            title: '操作',
            align: 'center',
            width: 120,
            toolbar: '#databar'
        }]
    ];

    // 监听列表开关
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            table = layui.table,
            $ = layui.jquery;
        form.on('switch(status)', function (obj) {
            $.post('/admins/links/save_edit', { id: this.value, status: obj.elem.checked ? 0 : 1 }, function (res) {
                if (res.code) {
                    layer.alert(res.msg, { icon: 2 });
                    setTimeout(function () {
                        table.reload('dataTable');
                        layer.close();
                    }, 1000);
                    return;
                }
                layer.msg(res.msg);
            }, 'json');
            return false;
        });
    });
</script>
{/block}